Fixing bug with single and double quotes inside values#7
Open
DmitryMK wants to merge 1 commit into
Open
Conversation
There was a problem hiding this comment.
Pull request overview
This PR addresses parsing/serialization edge cases where string values contain embedded single or double quotes, improving the filter language’s ability to round-trip such values reliably.
Changes:
- Extend string token regex to accept escaped quotes within quoted literals.
- Update parsing to unescape embedded quotes and update serialization to escape embedded double quotes.
- Add tests covering validation, parsing, and stringification for values containing escaped quotes; bump version to
0.2.1and update changelog.
Reviewed changes
Copilot reviewed 7 out of 7 changed files in this pull request and generated 5 comments.
Show a summary per file
| File | Description |
|---|---|
src/utils/filterRegex.ts |
Expands itemString regex to allow escaped quotes inside quoted string literals. |
src/utils/filterExpression.ts |
Unescapes embedded quotes during parsing; adjusts condition reading to respect escape characters; escapes " during serialization. |
test/validateFilterString.test.ts |
Adds validation tests for filter strings containing escaped quotes. |
test/stringToFilter.test.ts |
Adds parsing + round-trip tests for escaped quotes in string values. |
test/filterToString.test.ts |
Adds serialization test to ensure embedded " are escaped in output. |
package.json |
Bumps package version to 0.2.1. |
CHANGELOG.md |
Adds 0.2.1 entry describing the quote-handling bugfix. |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
Comment on lines
119
to
123
| return splitCommaRespectingQuotes(items).map((item) => { | ||
| const match = item.match(/^(["'])(.*)\1$/s); | ||
| if (match === null) { | ||
| throw new Error(`Invalid string value ${item}`); | ||
| } |
Comment on lines
+454
to
+455
| const escapedValues = value.map((v) => (v as string).replace(/"/g, '\\"')); | ||
| valueString = `("${escapedValues.join('", "')}")`; |
Comment on lines
+460
to
+462
| // Escape double quotes in the string value | ||
| const escapedValue = value.replace(/"/g, '\\"'); | ||
| valueString = `"${escapedValue}"`; |
Comment on lines
+108
to
+111
| const quote = match[1]; | ||
| const value = match[2]; | ||
| const escapedQuote = quote === '"' ? '\\\\"' : "\\\\'"; | ||
| return value.replace(new RegExp(escapedQuote, "g"), quote); |
Comment on lines
+124
to
+127
| const quote = match[1]; | ||
| const value = match[2]; | ||
| const escapedQuote = quote === '"' ? '\\\\"' : "\\\\'"; | ||
| return value.replace(new RegExp(escapedQuote, "g"), quote); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
No description provided.